import java.util.LinkedList;




public class HandEvaluator 
{
	public HandEvaluator()
	{
	}
	public double preFlopHandRank(LinkedList<Card> h){
		// Stats taken from
		// http://www.caniwin.com/texasholdem/preflop/heads-up.php
		// for the sake of comparison we order the cards by rank
		Card swapCard;
		if(h.get(0).getNumber() < h.get(0).getNumber()){
			swapCard = h.get(0);
			h.set(0, h.get(1));
			h.set(1, swapCard);
		}
		
		double rating = 0.0;
		
		// same suit table
		if(h.get(0).getSuit() == h.get(1).getSuit()){
			// first card is A
			if(h.get(0).getNumber() == 1){
				if(h.get(1).getNumber() == 13)
					rating = 62.4;
				else if(h.get(1).getNumber() == 12)
					rating = 61.47;
				else if(h.get(1).getNumber() == 11)
					rating = 60.58;
				else if(h.get(1).getNumber() == 10)
					rating = 58.63;
				else if(h.get(1).getNumber() == 9)
					rating = 56.79;
				else if(h.get(1).getNumber() == 8)
					rating = 55.84;
				else if(h.get(1).getNumber() == 7)
					rating = 54.8;
				else if(h.get(1).getNumber() == 6)
					rating = 53.83;
				else if(h.get(1).getNumber() == 5)
					rating = 52.88;
				else if(h.get(1).getNumber() == 4)
					rating = 52.07;
				else if(h.get(1).getNumber() == 3)
					rating = 51.23;
				else if(h.get(1).getNumber() == 2)
					rating = 66.21;	
			}
			// first card is K
			if(h.get(0).getNumber() == 13){
				if(h.get(1).getNumber() == 12)
					rating = 62.4;
				else if(h.get(1).getNumber() == 11)
					rating = 61.47;
				else if(h.get(1).getNumber() == 10)
					rating = 60.58;
				else if(h.get(1).getNumber() == 9)
					rating = 58.63;
				else if(h.get(1).getNumber() == 8)
					rating = 56.79;
				else if(h.get(1).getNumber() == 7)
					rating = 55.84;
				else if(h.get(1).getNumber() == 6)
					rating = 54.8;
				else if(h.get(1).getNumber() == 5)
					rating = 53.83;
				else if(h.get(1).getNumber() == 4)
					rating = 52.88;
				else if(h.get(1).getNumber() == 3)
					rating = 52.07;
				else if(h.get(1).getNumber() == 2)
					rating = 51.23;
				else if(h.get(1).getNumber() == 1)
					rating = 66.21;	
			}
			// first card is Q
			else if(h.get(0).getNumber() == 12){
				if(h.get(1).getNumber() == 11)
					rating = 59.07;
				else if(h.get(1).getNumber() == 10)
					rating = 58.17;
				else if(h.get(1).getNumber() == 9)
					rating = 56.22;
				else if(h.get(1).getNumber() == 8)
					rating = 54.41;
				else if(h.get(1).getNumber() == 7)
					rating = 52.52;
				else if(h.get(1).getNumber() == 6)
					rating = 51.67;
				else if(h.get(1).getNumber() == 5)
					rating = 50.71;
				else if(h.get(1).getNumber() == 4)
					rating = 49.76;
				else if(h.get(1).getNumber() == 3)
					rating = 48.93;
				else if(h.get(1).getNumber() == 2)
					rating = 48.1;
				else if(h.get(1).getNumber() == 1)
					rating = 65.31;	
			}
			// first card is J
			else if(h.get(0).getNumber() == 11){
				if(h.get(1).getNumber() == 10)
					rating = 56.15;
				else if(h.get(1).getNumber() == 9)
					rating = 54.11;
				else if(h.get(1).getNumber() == 8)
					rating = 52.31;
				else if(h.get(1).getNumber() == 7)
					rating = 50.45;
				else if(h.get(1).getNumber() == 6)
					rating = 48.57;
				else if(h.get(1).getNumber() == 5)
					rating = 47.82;
				else if(h.get(1).getNumber() == 4)
					rating = 46.86;
				else if(h.get(1).getNumber() == 3)
					rating = 46.04;
				else if(h.get(1).getNumber() == 2)
					rating = 45.2;
				else if(h.get(1).getNumber() == 1)
					rating = 64.39;	
			}
			// first card is 10
			else if(h.get(0).getNumber() == 10){
				if(h.get(1).getNumber() == 9)
					rating = 52.37;
				else if(h.get(1).getNumber() == 8)
					rating = 50.5;
				else if(h.get(1).getNumber() == 7)
					rating = 48.65;
				else if(h.get(1).getNumber() == 6)
					rating = 46.8;
				else if(h.get(1).getNumber() == 5)
					rating = 44.93;
				else if(h.get(1).getNumber() == 4)
					rating = 44.2;
				else if(h.get(1).getNumber() == 3)
					rating = 43.37;
				else if(h.get(1).getNumber() == 2)
					rating = 42.54;
				else if(h.get(1).getNumber() == 1)
					rating = 63.48;	
			}
			// first card is 9
			else if(h.get(0).getNumber() == 9){
				if(h.get(1).getNumber() == 8)
					rating = 48.85;
				else if(h.get(1).getNumber() == 7)
					rating = 46.99;
				else if(h.get(1).getNumber() == 6)
					rating = 45.15;
				else if(h.get(1).getNumber() == 5)
					rating = 43.31;
				else if(h.get(1).getNumber() == 4)
					rating = 41.4;
				else if(h.get(1).getNumber() == 3)
					rating = 40.8;
				else if(h.get(1).getNumber() == 2)
					rating = 39.97;
				else if(h.get(1).getNumber() == 1)
					rating = 61.5;	
			}
			// first card is 8
			else if(h.get(0).getNumber() == 8){
				if(h.get(1).getNumber() == 7)
					rating = 45.68;
				else if(h.get(1).getNumber() == 6)
					rating = 43.81;
				else if(h.get(1).getNumber() == 5)
					rating = 41.99;
				else if(h.get(1).getNumber() == 4)
					rating = 40.1;
				else if(h.get(1).getNumber() == 3)
					rating = 38.28;
				else if(h.get(1).getNumber() == 2)
					rating = 37.67;
				else if(h.get(1).getNumber() == 1)
					rating = 60.5;	
			}
			// first card is 7
			else if(h.get(0).getNumber() == 7){
				if(h.get(1).getNumber() == 6)
					rating = 42.82;
				else if(h.get(1).getNumber() == 5)
					rating = 40.97;
				else if(h.get(1).getNumber() == 4)
					rating = 39.1;
				else if(h.get(1).getNumber() == 3)
					rating = 37.3;
				else if(h.get(1).getNumber() == 2)
					rating = 35.43;
				else if(h.get(1).getNumber() == 1)
					rating = 59.38;	
			}
			// first card is 6
			else if(h.get(0).getNumber() == 6){
				if(h.get(1).getNumber() == 5)
					rating = 40.34;
				else if(h.get(1).getNumber() == 4)
					rating = 38.48;
				else if(h.get(1).getNumber() == 3)
					rating = 36.68;
				else if(h.get(1).getNumber() == 2)
					rating = 34.83;
				else if(h.get(1).getNumber() == 1)
					rating = 58.17;	
			}
			// first card is 5
			else if(h.get(0).getNumber() == 5){
				if(h.get(1).getNumber() == 4)
					rating = 38.53;
				else if(h.get(1).getNumber() == 3)
					rating = 36.75;
				else if(h.get(1).getNumber() == 2)
					rating = 34.92;
				else if(h.get(1).getNumber() == 1)
					rating = 58.06;	
			}
			// first card is 4
			else if(h.get(0).getNumber() == 4){
				if(h.get(1).getNumber() == 3)
					rating = 35.72;
				else if(h.get(1).getNumber() == 2)
					rating = 33.91;
				else if(h.get(1).getNumber() == 1)
					rating = 57.13;	
			}
			// first card is 3
			else if(h.get(0).getNumber() == 3){
				if(h.get(1).getNumber() == 2)
					rating = 33.09;
				else if(h.get(1).getNumber() == 1)
					rating = 56.33;	
			}
			// first card is 2
			else if(h.get(0).getNumber() == 2){
				if(h.get(1).getNumber() == 1)
					rating = 55.5;
			}
			
		}
		
		// different suit
		else{
			// pairs first diff suit
			if(h.get(0).getNumber() == h.get(1).getNumber()){
				if(h.get(0).getNumber() == 1)
					rating = 84.9;
				else if(h.get(0).getNumber() == 13)
					rating = 82.1;
				else if(h.get(0).getNumber() == 12)
					rating = 79.6;
				else if(h.get(1).getNumber() == 11)
					rating = 77.2;
				else if(h.get(0).getNumber() == 10)
					rating = 74.7;
				else if(h.get(0).getNumber() == 9)
					rating = 71.7;
				else if(h.get(0).getNumber() == 8)
					rating = 68.7;
				else if(h.get(0).getNumber() == 7)
					rating = 65.3;
				else if(h.get(0).getNumber() == 6)
					rating = 62.7;
				else if(h.get(0).getNumber() == 5)
					rating = 59.6;
				else if(h.get(0).getNumber() == 4)
					rating = 56.3;
				else if(h.get(0).getNumber() == 3)
					rating = 52.8;
				else if(h.get(0).getNumber() == 2)
					rating = 49.4;
			}
			// non pairs diff suit
			else {
				// first card is K
				if(h.get(0).getNumber() == 13){
					if(h.get(1).getNumber() == 12)
						rating = 60.43;
					else if(h.get(1).getNumber() == 11)
						rating = 59.44;
					else if(h.get(1).getNumber() == 10)
						rating = 58.49;
					else if(h.get(1).getNumber() == 9)
						rating = 56.4;
					else if(h.get(1).getNumber() == 8)
						rating = 54.43;
					else if(h.get(1).getNumber() == 7)
						rating = 53.41;
					else if(h.get(1).getNumber() == 6)
						rating = 52.29;
					else if(h.get(1).getNumber() == 5)
						rating = 51.25;
					else if(h.get(1).getNumber() == 4)
						rating = 50.22;
					else if(h.get(1).getNumber() == 3)
						rating = 49.33;
					else if(h.get(1).getNumber() == 2)
						rating = 48.42;
					else if(h.get(1).getNumber() == 1)
						rating = 64.46;	
				}
				// first card is Q
				else if(h.get(0).getNumber() == 12){
					if(h.get(1).getNumber() == 11)
						rating = 56.9;
					else if(h.get(1).getNumber() == 10)
						rating = 55.94;
					else if(h.get(1).getNumber() == 9)
						rating = 53.86;
					else if(h.get(1).getNumber() == 8)
						rating = 51.93;
					else if(h.get(1).getNumber() == 7)
						rating = 49.9;
					else if(h.get(1).getNumber() == 6)
						rating = 48.99;
					else if(h.get(1).getNumber() == 5)
						rating = 47.95;
					else if(h.get(1).getNumber() == 4)
						rating = 46.92;
					else if(h.get(1).getNumber() == 3)
						rating = 46.02;
					else if(h.get(1).getNumber() == 2)
						rating = 45.1;
					else if(h.get(1).getNumber() == 1)
						rating = 63.5;	
				}
				// first card is J
				else if(h.get(0).getNumber() == 11){
					if(h.get(1).getNumber() == 10)
						rating = 53.82;
					else if(h.get(1).getNumber() == 9)
						rating = 51.63;
					else if(h.get(1).getNumber() == 8)
						rating = 49.71;
					else if(h.get(1).getNumber() == 7)
						rating = 47.72;
					else if(h.get(1).getNumber() == 6)
						rating = 45.71;
					else if(h.get(1).getNumber() == 5)
						rating = 44.9;
					else if(h.get(1).getNumber() == 4)
						rating = 43.86;
					else if(h.get(1).getNumber() == 3)
						rating = 42.96;
					else if(h.get(1).getNumber() == 2)
						rating = 42.04;
					else if(h.get(1).getNumber() == 1)
						rating = 62.53;	
				}
				// first card is 10
				else if(h.get(0).getNumber() == 10){
					if(h.get(1).getNumber() == 9)
						rating = 49.81;
					else if(h.get(1).getNumber() == 8)
						rating = 47.81;
					else if(h.get(1).getNumber() == 7)
						rating = 45.82;
					else if(h.get(1).getNumber() == 6)
						rating = 43.84;
					else if(h.get(1).getNumber() == 5)
						rating = 41.85;
					else if(h.get(1).getNumber() == 4)
						rating = 41.05;
					else if(h.get(1).getNumber() == 3)
						rating = 40.15;
					else if(h.get(1).getNumber() == 2)
						rating = 39.23;
					else if(h.get(1).getNumber() == 1)
						rating = 61.56;	
				}
				// first card is 9
				else if(h.get(0).getNumber() == 9){
					if(h.get(1).getNumber() == 8)
						rating = 46.06;
					else if(h.get(1).getNumber() == 7)
						rating = 44.07;
					else if(h.get(1).getNumber() == 6)
						rating = 42.1;
					else if(h.get(1).getNumber() == 5)
						rating = 40.13;
					else if(h.get(1).getNumber() == 4)
						rating = 38.08;
					else if(h.get(1).getNumber() == 3)
						rating = 37.42;
					else if(h.get(1).getNumber() == 2)
						rating = 36.51;
					else if(h.get(1).getNumber() == 1)
						rating = 59.44;	
				}
				// first card is 8
				else if(h.get(0).getNumber() == 8){
					if(h.get(1).getNumber() == 7)
						rating = 42.69;
					else if(h.get(1).getNumber() == 6)
						rating = 40.69;
					else if(h.get(1).getNumber() == 5)
						rating = 38.74;
					else if(h.get(1).getNumber() == 4)
						rating = 36.7;
					else if(h.get(1).getNumber() == 3)
						rating = 34.74;
					else if(h.get(1).getNumber() == 2)
						rating = 34.08;
					else if(h.get(1).getNumber() == 1)
						rating = 58.37;	
				}
				// first card is 7
				else if(h.get(0).getNumber() == 7){
					if(h.get(1).getNumber() == 6)
						rating = 39.65;
					else if(h.get(1).getNumber() == 5)
						rating = 37.67;
					else if(h.get(1).getNumber() == 4)
						rating = 35.66;
					else if(h.get(1).getNumber() == 3)
						rating = 33.71;
					else if(h.get(1).getNumber() == 2)
						rating = 31.71;
					else if(h.get(1).getNumber() == 1)
						rating = 57.16;	
				}
				// first card is 6
				else if(h.get(0).getNumber() == 6){
					if(h.get(1).getNumber() == 5)
						rating = 37.01;
					else if(h.get(1).getNumber() == 4)
						rating = 35.0;
					else if(h.get(1).getNumber() == 3)
						rating = 33.06;
					else if(h.get(1).getNumber() == 2)
						rating = 31.07;
					else if(h.get(1).getNumber() == 1)
						rating = 55.87;	
				}
				// first card is 5
				else if(h.get(0).getNumber() == 5){
					if(h.get(1).getNumber() == 4)
						rating = 35.07;
					else if(h.get(1).getNumber() == 3)
						rating = 33.16;
					else if(h.get(1).getNumber() == 2)
						rating = 31.19;
					else if(h.get(1).getNumber() == 1)
						rating = 55.74;	
				}
				// first card is 4
				else if(h.get(0).getNumber() == 4){
					if(h.get(1).getNumber() == 3)
						rating = 32.06;
					else if(h.get(1).getNumber() == 2)
						rating = 30.11;
					else if(h.get(1).getNumber() == 1)
						rating = 54.73;	
				}
				// first card is 3
				else if(h.get(0).getNumber() == 3){
					if(h.get(1).getNumber() == 2)
						rating = 29.23;
					else if(h.get(1).getNumber() == 1)
						rating = 53.85;	
				}
				// first card is 2
				else if(h.get(0).getNumber() == 2){
					if(h.get(1).getNumber() == 1)
						rating = 52.94;
				}
			}
		}
		
		return rating;
	}

}
